 <template>
  <el-form label-width="100px" class="demo-ruleForm">
    <el-form-item label="标题名称" prop="name">
      <el-input v-model="titlename"></el-input>
    </el-form-item>
    <el-form-item label="链接地址" prop="name">
      <el-input v-model="myhttp"></el-input>
      <span>（示列：http://www.baidu.com)</span>
    </el-form-item>

    <el-form-item label="图片上传">
      <el-upload
        class="upload-demo"
        action="/ads/AddAd"
        :limit="1"
        :on-exceed="handleExceed"
        :on-success="success"
        multiple
      >
        <el-button size="small" type="primary">点击上传</el-button>
        <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过2M</div>
      </el-upload>
    </el-form-item>

    <el-form-item label="详细介绍" prop="desc">
      <el-input type="textarea" v-model="msg"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="nowchange">立即修改</el-button>
    </el-form-item>
  </el-form>
</template>
<script>
import Axios from "axios";
export default {
  data() {
    return {
      titlename: "",
      myhttp: "",
      msg: "",
      img: ""
    };
  },
  mounted() {
    this.getchanged();
  },
  methods: {
    getchanged() {
      const id = this.$route.params;
      Axios.get("/ads/getone", { params: { _id: id.id } }).then(res => {
    
        const msgs = res.data[0];
        this.titlename = msgs.add_name;
        this.img = msgs.add_img;
        this.myhttp = msgs.add_http;
        this.msg = msgs.add_msg;
      });
    },
    handleExceed() {
      alert("文件超出大小限制");
    },
    success(file) {
      this.img = file.file[0].path;
    },
    nowchange(){
       const a = {
           _id:this.$route.params.id,
        add_name: this.titlename,
        add_img: this.img,
        add_http: this.myhttp,
        add_msg: this.msg
      };
      Axios.post("/ads/cgnow", a).then((res)=>{
       if(res.data){
             this.$router.push('/All/Ad')
       }
        
      })
    }
  }
};
</script>

<style>
</style>